﻿

/**
 * CartItem Class
 * 
 * Tạo cấu trúc của giỏ hàng
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MLM.Data;
using MLM.AdminCP.Class;


namespace MLM
{
    public static partial class MLM
    {
        public class CartItem : IEquatable<CartItem>
        {
            #region Properties

            // Tạo thuộc tính getter và setter.
            public long Quantity { get; set; }

            private long _productId;
            private long _CountryId;
            private long _USerID;
            public long ProductId
            {
                get { return _productId; }
                set
                {
                    _product = null;
                    _productId = value;
                }
            }
            public long USerID
            {
                get { return _USerID; }
                set
                {
                    _product = null;
                    _USerID = value;
                }
            }
            public long CountryID
            {
                get { return _CountryId; }
                set
                {
                    _product = null;
                    _CountryId = value;
                }
            }

            private Product _product = null;

            public Product Prod
            {
                get
                {
                    if (_product == null)
                    {
                        _product = new Product(ProductId, CountryID);
                    }
                    return _product;
                }
            }

            //public string Description
            //{
            //    get { return Prod.Description; }
            //}
            public string VAT
            {
                get { return Prod.VAT; }
            }
            public string Points
            {
                get { return Prod.Points; }
            }
            public string Name
            {
                get { return Prod.Name; }
            }

            public decimal PointsTotal
            {
                get { return (decimal.Parse(Prod.Points) * Quantity); }
            }
            public string UnitPrice
            {
                get { return Prod.Price; }
            }

            public decimal PriceWithTax {
                get { return Prod.PriceTax; }
            }


            /// <summary>
            /// total price =  this.Price * Quantity
            /// </summary>
            public decimal TotalPriceTax
            {
                get { return PriceWithTax*Quantity; }
            }
            /// <summary>
            /// total price =  this.Price * Quantity
            /// </summary>
            public string TotalPrice 
            {
                get { return (double.Parse(UnitPrice) * Quantity).ToString(); }
            }

            #endregion

            public CartItem(long productId)
            {
                this.ProductId = productId;
                this.CountryID = CountryID;

            }
            public CartItem(long productId, long CountryID, long UserID)
            {
                this.ProductId = productId;
                this.CountryID = CountryID;
                this.USerID = UserID;
            }
            public bool Equals(CartItem item)
            {
                return item.ProductId == this.ProductId;
            }
        }
    }
}